/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utilities;

/**
 *
 * @author VietLH
 */
public class ValidateInput {

    public boolean checkIsEmpty(String text) {
        if (text != null && text.compareTo("") != 0) {
            return false;
        }
        return true;
    }
    public boolean checkIsEmpty(char[] password) {
        String cPassword="";
        for(int i=0;i<password.length;i++){
            cPassword+=password[i];
        }
        if (password != null && cPassword.compareTo("") != 0) {
            return false;
        }
        return true;
    }
    public boolean checkIsNumber(String text) {
//        try {
//            long i = Long.parseLong(text);
//        } catch (Exception e) {
//            return false;
//        }
//        return true;
        for (int i = 0; i < text.length(); i++) {
            //If we find a non-digit character we return false.
            if (!Character.isDigit(text.charAt(i)))
                return false;
        }
       
        return true;
    }
    public String convertSpecialCharacters(String text){
        String converted=text.replaceAll("'", "''");
        return converted;
    }
    public boolean checkMatchPassword(char[] password,char[] confirmPass){
        String cPassword="";
        for(int i=0;i<password.length;i++){
            cPassword+=password[i];
        }
        String cConfirmPassword="";
        for(int i=0;i<confirmPass.length;i++){
            cConfirmPassword+=confirmPass[i];
        }
        if(cPassword.compareTo(cConfirmPassword)==0){
            return true;
        }
        return false;
    }
    public boolean isExistSpecialCharacter(char[] password){
        String cPassword="";
        for(int i=0;i<password.length;i++){
            cPassword+=password[i];
        }
        if(cPassword.contains("'")){
            return true;
        }
        return false;
    }
    
}
